package com.jeesite.modules.app.util.wx;


import java.util.concurrent.TimeUnit;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;

public class NioWebSocketChannelInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		pipeline.addLast("logger",new LoggingHandler("DEBUG"));
		pipeline.addLast("idleStateHandler",new IdleStateHandler(5, 0,0,TimeUnit.SECONDS));
		pipeline.addLast("idleStateTrigger",new ServerIdleStateTrigger());
		pipeline.addLast("http-codec",new HttpServerCodec());
		pipeline.addLast("aggregator",new HttpObjectAggregator(65535));
		pipeline.addLast("http-chunked",new ChunkedWriteHandler());
		pipeline.addLast("decoder",new StringDecoder());
		pipeline.addLast("encoder",new StringEncoder());
		pipeline.addLast("handler",new NioWebSocketHandler());
	}

}
